//
//  IndexViewController.swift
//  photoTool
//
//  Created by 刘清元 on 2022/8/22.
//

import UIKit
import SnapKit
import WCDBSwift
class IndexViewController: UIViewController {
    
    private let titleArr:[String] = ["扫描相册","查看相册","查看重复图片","图片转heic"/*,"清空本地数据"*/]
    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        print(FileTool.init().getDocumentPath())
        UserDefaults.standard.setValue(10, forKey: "cellValue")
        // 创建数据表
        try! FileTool().getDb().create(table: "image", of: ImageModel.self)
        try! FileTool().getDb().create(table: "repeated", of: RepeatedModel.self)
        view.backgroundColor = .white
        mainTable.listArr = titleArr
    }
   
    lazy var mainTable: UUTableView = {
        let tableView = UUTableView.init(frame: .zero, style: .plain)
        view?.addSubview(tableView)
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
        tableView.snp.makeConstraints { make in
            make.edges.equalToSuperview()
        }
        tableView.cellForRow { indexPath in
            let cell = tableView.dequeueReusableCell(withIdentifier: "cell")
            cell?.textLabel?.text = self.titleArr[indexPath.row]
            return cell!
        }
        
        tableView.cellItemDidSelected { indexPath in
            if indexPath.row == 0{
                // 扫描相册
                let alert = UIAlertController.init(title: "提示", message: "是否扫描相册", preferredStyle: .alert)
                let cancelAction = UIAlertAction.init(title: "取消", style: .cancel)
                alert.addAction(cancelAction)
                let oneAction = UIAlertAction.init(title: "不扫描", style: .default) { action in
                    let VC = PhotoListViewController.init()
                    VC.need_scan = false
                    self.navigationController?.pushViewController(VC, animated: true)
                }
                alert.addAction(oneAction)
                let sureAction = UIAlertAction.init(title: "确定", style: .default) { action in
                    let VC = PhotoListViewController.init()
                    VC.need_scan = true
                    self.navigationController?.pushViewController(VC, animated: true)
                }
                alert.addAction(sureAction)
                self.present(alert, animated: true)
            }else if indexPath.row == 1{
                self.navigationController?.pushViewController(AlbumListViewController.init(), animated: true)
            }else if indexPath.row == 2{
                let VC = AlbumListViewController()
                VC.type = 1
                self.navigationController?.pushViewController(VC, animated: true)
            }else if indexPath.row == 3{
                // 图片转heic
                let VC = HeicViewController.init()
                self.navigationController?.pushViewController(VC, animated: true)
            }else{
            }
        }
        return tableView
    }()
}
